{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##从已有的变量设置设计空间，给定变化范围百分比%a，计算公式如下：\n",
    "\n",
    "正数：\n",
    "\n",
    "(1-%a)*var, (1+%a)*var\n",
    "\n",
    "负数：\n",
    "\n",
    "(1+%a)*var, (1-%a)*var"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.1709432007185761 True\n",
      "0.15545560745687814 True\n",
      "0.158927725977942 True\n",
      "0.13802848144858523 True\n",
      "0.14467404644947993 True\n",
      "0.14386739850251995 True\n",
      "-0.1709432007185761 True\n",
      "-0.15545560743592157 True\n",
      "-0.15892772608044667 True\n",
      "-0.13802848131715453 True\n",
      "-0.14467404654268579 True\n",
      "-0.14386739846252472 True\n",
      "<x1>  1.5384888064671851e-01    1.8803752079043373e-01</x1>\n",
      "<x2>  1.3991004671119034e-01    1.7100116820256597e-01</x2>\n",
      "<x3>  1.4303495338014779e-01    1.7482049857573620e-01</x3>\n",
      "<x4>  1.2422563330372671e-01    1.5183132959344378e-01</x4>\n",
      "<x5>  1.3020664180453193e-01    1.5914145109442793e-01</x5>\n",
      "<x6>  1.2948065865226796e-01    1.5825413835277197e-01</x6>\n",
      "<x7> -1.8803752079043373e-01   -1.5384888064671851e-01</x7>\n",
      "<x8> -1.7100116817951375e-01   -1.3991004669232943e-01</x8>\n",
      "<x9> -1.7482049868849134e-01   -1.4303495347240200e-01</x9>\n",
      "<x10> -1.5183132944887001e-01   -1.2422563318543908e-01</x10>\n",
      "<x11> -1.5914145119695439e-01   -1.3020664188841721e-01</x11>\n",
      "<x12> -1.5825413830877721e-01   -1.2948065861627225e-01</x12>\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import os\n",
    "\n",
    "ratio = 0.1\n",
    "\n",
    "#must be 1D-ndarray\n",
    "dv = np.loadtxt('dv.csv')\n",
    "\n",
    "#varRange\n",
    "varRang = np.zeros((len(dv),2)) #init\n",
    "for var,vr in zip(dv,varRang):\n",
    "    if var >= 0.0:\n",
    "        vr[0] = (1.0-ratio)*var\n",
    "        vr[1] = (1.0+ratio)*var\n",
    "    else:\n",
    "        vr[0] = (1.0+ratio)*var\n",
    "        vr[1] = (1.0-ratio)*var    \n",
    "    print(var,vr[0]<=vr[1])\n",
    "\n",
    "n = 1\n",
    "for vr in varRang:\n",
    "    print('<x%d>%24.16e  %24.16e</x%d>' % (n,vr[0],vr[1],n))\n",
    "    n += 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0.],\n",
       "       [0., 0.],\n",
       "       [0., 0.],\n",
       "       [0., 0.],\n",
       "       [0., 0.],\n",
       "       [0., 0.],\n",
       "       [0., 0.],\n",
       "       [0., 0.],\n",
       "       [0., 0.],\n",
       "       [0., 0.],\n",
       "       [0., 0.],\n",
       "       [0., 0.]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "varRang"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
